#!/bin/bash
#
#	Author	:	whlttst
#	Date	:	20230614
#	Description:	Program controller script demo
######################################################
set -e
#
#	Load environment varialbes
# get current script work path
BASE_DIR=$(cd $(dirname $0); pwd)

# define service array
APP_SERVERS=(neu-registry neu-gateway dcim-sap)

# define start function include all services
function allstart() {
  for server in ${APP_SERVERS[@]}
  do
    echo start-$server
  done
}

function start() {
  for server in ${APP_SERVERS[@]}
  do
  if [[ "$1" == "$server" ]];then
    echo start-$1
  else
    continue
    echo "$1 not in the array" 
  fi
  done
}

function allstop() {
  for server in ${APP_SERVERS[@]}
  do
    echo stop-$server
  done
}

# judge argument number
if [ $# -eq 2 ];
then
# entrypoint
case $2 in
start)
if [ $1 = "all" ];then
allstart
else
  start $1
fi
;;
stop)
stop
;;
*)
echo $"Usage: $0  {start|stop}"
;;
esac
else
echo $"Usage: $0 {all|registry|gateway} start"
exit 1
fi